package cn.edu.swu.miniwebsvr.core;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class Parameter {
    private String method;
    private String url;
    private Map<String ,String> urlParams = new HashMap<>();    // url参数集
    private Map<String ,String> bodyParams = new HashMap<>();   // body部分参数集
    private Map<String ,String> headers = new HashMap<>();      // header部分

    // [222024321072041/王耀东] 补充必要的构造函数、setter、getter方法

    public Map<String,String> getAllParams(){
        /**
         * 获取全部Param
         */
        Map<String,String> allParams = new HashMap<>();
        // 将urlParams和bodyParams内容复制到allParams中
        allParams.putAll(urlParams);
        allParams.putAll(bodyParams);
        // 返回不可修改的包含所有Patams的Map
        return Collections.unmodifiableMap(allParams);
    }

    public String getParam(String name){
        /**
         * 按key值在所有Param中查询得到
         */
        if (bodyParams.containsKey(name)){
            return bodyParams.get(name);
        }
        return urlParams.get(name);
    }

    public void setBodyParams(Map<String, String> bodyParams) {
        this.bodyParams = bodyParams;
    }

    public void setUrlParams(String key,String value) {
        urlParams.put(key, value);
    }

    public Map<String,String> getHeaders(){
        return headers;
    }

    public void setHeaders(String key,String value) {
        headers.put(key,value);
    }


    public String getMethod(){
        return this.method;
    }

    public void setMethod(String method){
        this.method = method;
    }

    public String getUrl(){
        return this.url;
    }

    public void setUrl(String url){
        this.url = url;
    }

}
